﻿var app = angular.module("app", ["xeditable"]);
app.run(function (editableOptions) {
    editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
});

app.controller('EditableRowCtrl', function ($scope, $filter, $http) {
    $('#ajax_loader').show();
    
    $http.get('/user/get').success(function (data) {
        $scope.users = data;
        $('#ajax_loader').hide();
    })
    .error(function () {
        $('#ajax_loader').hide();
    });

    // remove user
    $scope.removeUser = function (index) {
        var deluser = $scope.users[index];
        $('#myModal-' + index).modal('toggle');
        $('.modal-backdrop').remove();
        return $http.post('/user/delete', deluser).success(function () {
            $scope.users.splice(index, 1);
        });
    };

    // add user
    $scope.addUser = function () {
        $scope.inserted = {
            id: '',
            name: ''
        };
        $scope.users.push($scope.inserted);
    };
});